<?php
    include "../../../config.php";
    require_once("../config.php");

    Header("content-type: application/x-javascript");

    $url = $CFG->wwwroot;
?>

function folio_tags_autocomplete_init() {
YAHOO.example.ACFlatData = new function(){
    // Define a custom formatter function
    this.fnCustomFormatter = function(oResultItem, sQuery) {
        var sKey = oResultItem[0];
        var nQuantity = oResultItem[1];
        var sKeyQuery = sKey.substr(0, sQuery.length);
        var sKeyRemainder = sKey.substr(sQuery.length);
        var aMarkup = ["<div class='sample-result'><div class='sample-quantity'>",
            nQuantity,
            "</div><span class='sample-query'>",
            sKeyQuery,
            "</span>",
            sKeyRemainder,
            "</div>"];
        return (aMarkup.join(""));
    };

    // Instantiate one XHR DataSource and define schema as an array:
    //     ["Record Delimiter",
    //     "Field Delimiter"]
    this.oACDS = new YAHOO.widget.DS_XHR("<?php echo $url; ?>mod/folio/ajax/tags_select.php", [";", ","]);
    this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
    this.oACDS.maxCacheEntries = 60;
    this.oACDS.queryMatchSubset = true;

    // Instantiate third AutoComplete
    this.oAutoComp = new YAHOO.widget.AutoComplete('ysearchinput_edit','ysearchcontainer', this.oACDS);
    this.oAutoComp.queryDelay = 0;
    this.oAutoComp.delimChar = ";";
    this.oAutoComp.prehighlightClassName = "yui-ac-prehighlight";
    this.oAutoComp.formatResult = this.fnCustomFormatter;
};
}
